######################################################################################
# Title 	 : Map of number of studies planning to recruit participants in each country
# Manuscript Ref : Figure 3B of the manuscript
# Version	 : R version 3.6.3 (2020-02-29)
# Note: This script requires prepare_data_for_figure_3b.do be run first
######################################################################################

library(tmap)
library(tmaptools)
library(tidyverse)
library(readr)
library(colorspace)
library(devEMF)

#Set working directory
setwd ("filepath")

#Load in country number data
country_nums <- read_delim("data_mapping_country_numbers.csv", delim = ",") 

#Load in World data from tmap package
data(World)

#Combine world data and country number data
combined_data <- merge(World, country_nums,by="iso_a3",all = TRUE)

#Select mapping style
tmap_style("natural")

#Prepare map
tm_shape(combined_data) +
  tm_polygons("ctry_total_total_studies_cat",
              style="cat",
              labels = c("1", "2-3", "4-5", "6-10", ">10"),
              showNA = FALSE,
              colorNA = "grey",
              title = "Number studies",
              palette = "OrRd",)  + 
  tm_legend(legend.position = c("left", "bottom"))
dev.print("All_studies_map1.pdf",device=pdf)